// Compute the dis buffer

#include "./src/shared.h"

// Compare depth values instead of ec?

samplerRect dsECHi;
samplerRect dsNormHi;

samplerRect dsECLo;
samplerRect dsNormLo;

void main (void)
{
	vec3 normHi = normalize(textureRect(dsNormHi, gl_FragCoord));
	vec4 positionShadow = textureRect(dsECHi, gl_FragCoord);
	vec3 positionHi = vec3(positionShadow);

	vec2 loFragCoord = gl_FragCoord/LO_RES_REDUCTION;

	vec3 normLo = normalize(textureRect(dsNormLo, loFragCoord));
	positionShadow = textureRect(dsECLo, loFragCoord);
	vec3 positionLo = vec3(positionShadow);
    
	float scale = max(0, dot(normLo, normHi));
	float diffDis = length(positionLo - positionHi);
	//if (diffDis > 0.04025 || scale < 0.50) {
	if (diffDis > 0.4 || scale < 0.50) {
		gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
	} else {
		gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0);
	}
}

